<?php
/**
 * Created by PhpStorm.
 * User: wangsentao
 * Date: 2018/2/2
 * Time: 下午4:00
 */

namespace app\admin\service;

use app\common\Model\AdminUser;
use think\Db;

class SAdminUser
{
    public function checkUser($uid, $pwd)
    {
        // 查询用户 验证密码
        $res = Db::name(AdminUser::$tab_name)
            ->field('uid,acc_id,realname,phone,passwd,access_token')
            ->where('status', AdminUser::STATUS_NORMAL)
            ->where('uid', $uid)
            ->find();

        if (empty($res)) {
            return [
                'code' => '100000',
                'msg' => '账号不存在'
            ];
        }

        if ($res['passwd'] != $pwd) {
            return [
                'code' => '104001',
                'msg' => '账号密码不正确'
            ];
        }

        return [
            'code' => '000000',
            'data' => $res
        ];
    }

    public function getUidByAccId($acc_id)
    {
        $adminUser = \app\common\Model\AdminUser::where('acc_id', $acc_id)->find();
        return $adminUser->uid;
    }
}